package com.erification.web.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.erification.web.dao.UserDao;
import com.erification.web.model.User;
import com.erification.web.service.UserService;

@Service("userService")
public class UserServiceImpl implements UserService {
	@Resource
	private UserDao userDao;
	
	@Override
	public String saveUser(User user){
		if(userDao.getUser(user.getUsername()) == null) {
			userDao.save(user);
			return "注册成功";
		}
		return "用户名已存在";
	}
	
	@Override
	public void modifyPassword(String username,String passwd){
		User user = userDao.getUser(username);
		user.setPassword(passwd);
		userDao.update(user);
	}

	@Override
	public String validate(String username,String password) {
		User user = userDao.getUser(username);
		if(user == null) return "用户名不存在";
		if(!user.getPassword().equals(password)) return "密码错误";
		return "登录成功";
	}

	@Override
	public User getUser(String name) {
		return userDao.getUser(name);
	}
	
}
